var t = require("../../../@babel/runtime/helpers/defineProperty"), a = getApp();

Page({
    data: {
        active: 0,
        info: [],
        list: [],
        isLoadMore: !0,
        page: 1,
        total_page: 0
    },
    onLoad: function(t) {},
    tapActive: function(t) {
        this.init(), this.setData({
            active: t.currentTarget.dataset.key
        }), this.getData();
    },
    init: function() {
        this.setData({
            list: [],
            page: 1,
            total_page: 0
        });
    },
    onReady: function() {},
    onShow: function() {
        this.getUser();
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        console.log(this.data.isLoadMore), this.data.isLoadMore && this.getMoreData();
    },
    onShareAppMessage: function() {},
    checkTap: function(a) {
        var e = a.currentTarget.dataset.item, s = a.currentTarget.dataset.index;
        console.log(e, s), e.checked ? (this.setData(t({}, "list[" + s + "].checked", !1)), 
        console.log(this.data.list[s])) : this.getDaysLog(e.days, s);
    },
    getDaysLog: function(e, s) {
        var o = this;
        a._postNetWork({
            url: a.getNetAddresss("plugin.support-center.frontend.write-off-log.get-write-off-log"),
            data: {
                days: e
            },
            success: function(e) {
                var i, n = e.data;
                1 == n.result ? o.setData((t(i = {}, "list[" + s + "].checked", !0), t(i, "list[" + s + "].log", n.data.data), 
                t(i, "list[" + s + "].page", n.data.current_page), t(i, "list[" + s + "].last_page", n.data.last_page), 
                i)) : a.tips(n.msg);
            },
            fail: function(t) {
                console.log(t.msg);
            }
        });
    },
    moreLogTap: function(e) {
        var s = this, o = e.currentTarget.dataset.item, i = e.currentTarget.dataset.index;
        if (console.log(o, i), o.checked || !(o.page >= o.last_page)) {
            var n = Number(o.page) + 1;
            a._postNetWork({
                url: a.getNetAddresss("plugin.support-center.frontend.write-off-log.get-write-off-log"),
                data: {
                    days: o.days,
                    page: n
                },
                success: function(e) {
                    var o, n = e.data;
                    1 == n.result ? s.setData((t(o = {}, "list[" + i + "].checked", !0), t(o, "list[" + i + "].log", s.data.list[i].log.concat(n.data.data)), 
                    t(o, "list[" + i + "].page", n.data.current_page), t(o, "list[" + i + "].last_page", n.data.last_page), 
                    o)) : a.tips(n.msg);
                },
                fail: function(t) {
                    console.log(t.msg);
                }
            });
        }
    },
    getMoreData: function() {
        var t = this, e = "";
        e = 0 == this.data.active ? a.getNetAddresss("plugin.support-center.frontend.write-off-log.get-write-off-log-to-days") : a.getNetAddresss("plugin.support-center.frontend.write-off-log.get-quota-log"), 
        this.data.isLoadMore = !1, this.data.page >= this.data.total_page || (this.setData({
            page: this.data.page + 1
        }), a._postNetWork({
            url: e,
            data: {
                page: this.data.page
            },
            success: function(e) {
                var s = e.data;
                if (1 == s.result) {
                    var o = s.data.data;
                    t.setData({
                        list: t.data.list.concat(o)
                    }), t.data.isLoadMore = !0;
                } else a.tips(s.msg);
            },
            fail: function(t) {
                console.log(t.msg);
            }
        }));
    },
    getData: function() {
        var t = this, e = "", s = {
            page: this.data.page
        };
        e = 0 == this.data.active ? a.getNetAddresss("plugin.support-center.frontend.write-off-log.get-write-off-log-to-days") : a.getNetAddresss("plugin.support-center.frontend.write-off-log.get-quota-log"), 
        a._postNetWork({
            url: e,
            data: s,
            success: function(e) {
                var s = e.data;
                1 == s.result ? (t.setData({
                    list: s.data.data,
                    isLoadMore: !0,
                    total_page: s.data.last_page
                }), t.data.total_page || (t.data.total_page = 0)) : a.tips(s.msg);
            },
            fail: function(t) {
                console.log(t.msg);
            }
        });
    },
    getUser: function() {
        var t = this, e = a.getNetAddresss("plugin.support-center.frontend.write-off-log.get-member-info");
        a._postNetWork({
            url: e,
            success: function(e) {
                var s = e.data;
                1 == s.result ? (t.setData({
                    info: s.data
                }), wx.setNavigationBarTitle({
                    title: s.data.plugin_name
                }), t.getData()) : a.tips(s.msg);
            },
            fail: function(t) {
                console.log(t.msg);
            }
        });
    }
});